package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.product.ProductFeignClient;
import com.atguigu.gmall.model.to.CategoryAndChildTo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class indexController {
    @Autowired
    ProductFeignClient productFeignClient;

    @GetMapping("/")
    public String indexPage(Model model){
        Result<List<CategoryAndChildTo>> result = productFeignClient.getAllGategoryWithChilds();

        if (result.isOk()){
            List<CategoryAndChildTo> data = result.getData();
            model.addAttribute("list",data);
        }
        return "index/index";
    }
}
